﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using VSA.Entity;
using VSA.BLL;
using System.Web.Services.Protocols;
using System.IO;

namespace VSA.WebService
{
    [WebService(Namespace = "http://www.casengine.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
    public class MainService : System.Web.Services.WebService
    {
        //public VSASoapHeader vsaHeader = new VSASoapHeader();


        #region Function
        ////[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool AddFunction(Functions model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return FunctionsBLL.Add(model);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool UpdateFunction(Functions model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return FunctionsBLL.Update(model);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool DeleteFunction(int Did)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return FunctionsBLL.Delete(Did);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public Functions GetFunctionModel(int Did)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return FunctionsBLL.GetModel(Did);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetAllFunctionList()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return FunctionsBLL.GetAllList();
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet SaveFunctionData(String addData, String updateData, String deleteData)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                try
                {
                    if (!String.IsNullOrEmpty(addData))
                    {
                        String[] arrName = addData.Split(new Char[] { '|' });

                        foreach (string o in arrName)
                        {
                            Functions model = new Functions();
                            model.FunctionName = o;
                            FunctionsBLL.Add(model);
                        }
                    }

                    if (!String.IsNullOrEmpty(updateData))
                    {
                        String[] arrName = updateData.Split(new Char[] { '|' });

                        foreach (string o in arrName)
                        {
                            String[] arrValue = o.Split(new Char[] { ';' });

                            Functions model = FunctionsBLL.GetModel(Convert.ToInt32(arrValue[0]));
                            model.FunctionName = arrValue[1];
                            FunctionsBLL.Update(model);
                        }
                    }

                    if (!String.IsNullOrEmpty(deleteData))
                    {
                        String[] arrName = deleteData.Split(new Char[] { '|' });

                        foreach (string o in arrName)
                        {
                            FunctionsBLL.Delete(Convert.ToInt32(o));
                        }
                    }

                    return FunctionsBLL.GetAllList();
                }
                catch (Exception)
                {
                    return null;
                }
            //}
            //return null;
        }
        #endregion

        #region Activity
        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<Activity> GetActivityListArray(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ActivityBLL.GetModelList(strWhere);
            //}
            //return new List<Activity>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetActivityList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ActivityBLL.GetList(strWhere);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool UpdateActivity(VSA.Entity.Activity model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ActivityBLL.Update(model);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool AddActivity(VSA.Entity.Activity model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ActivityBLL.Add(model);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool DeleteActivity(int did)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ActivityBLL.Delete(did);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool BatchAddActivity(List<string> values)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                bool isSuccess = false;
                foreach (string value in values)
                {
                    if (!ActivityBLL.Contains(value))
                    {
                        Activity activity = new Activity();
                        activity.ActivityContent = value;
                        activity.CreateDate = DateTime.Now;
                        ActivityBLL.Add(activity);
                    }
                }
                return isSuccess;
            //}
            //return false;
        }
        #endregion

        #region  Company
        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public int GetMaxCompanyId()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyBLL.GetMaxId();
            //}
            //return -1;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool ExistsCompany(int CompanyId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyBLL.Exists(CompanyId);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public int AddCompany(Company model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyBLL.Add(model);
            //}
            //return -1;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void UpdateCompany(Company model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                CompanyBLL.Update(model);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void DeleteCompany(int CompanyId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                CompanyBLL.Delete(CompanyId);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public Company GetCompanyModel(int CompanyId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
            Company relation = new Company();
            if (CompanyId != int.MinValue)
            {
                relation = CompanyBLL.GetModel(CompanyId);
                relation.CompanyPerson = GetCompanyPersonMappingModelList("CompanyId=" + CompanyId);
                relation.CompanyProject = GetCompanyProjectMappingModelList("CompanyId=" + CompanyId);
            }
            else
            {
                relation.CompanyPerson = new List<CompanyPersonMapping>();
                relation.CompanyProject = new List<CompanyProjectMapping>();
            }
            relation.ReferenceActivityList = ActivityBLL.GetModelList("");
            relation.ReferenceContactPersonList = ContactPersonBLL.GetModelList("");
            relation.ReferenceProjectList = ProjectBLL.GetModelList("");
            return relation;
            //}
            //return null;
        }


        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public Company GetCompanyModelByCache(int CompanyId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyBLL.GetModelByCache(CompanyId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetCompanyList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyBLL.GetList(strWhere);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<Company> GetCompanyModelList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyBLL.GetModelList(strWhere);
            //}
            //return new List<Company>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<Company> DataTableToCompanyList(DataTable dt)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyBLL.DataTableToList(dt);
            //}
            //return new List<Company>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetAllCompanyList()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyBLL.GetAllList();
            //}
            //return null;
        }
        #endregion  Company

        #region  CompanyProjectMapping
        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public int GetMaxCompanyProjectMappingId()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyProjectMappingBLL.GetMaxId();
            //}
            //return -1;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool ExistsCompanyProjectMapping(int CompanyId, int ProjectId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyProjectMappingBLL.Exists(CompanyId, ProjectId);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void AddCompanyProjectMapping(CompanyProjectMapping model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                CompanyProjectMappingBLL.Add(model);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void UpdateCompanyProjectMapping(CompanyProjectMapping model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                CompanyProjectMappingBLL.Update(model);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void DeleteCompanyProjectMapping(int CompanyId, int ProjectId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                CompanyProjectMappingBLL.Delete(CompanyId, ProjectId);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public CompanyProjectMapping GetCompanyProjectMappingModel(int CompanyId, int ProjectId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyProjectMappingBLL.GetModel(CompanyId, ProjectId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public CompanyProjectMapping GetCompanyProjectMappingByCache(int CompanyId, int ProjectId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyProjectMappingBLL.GetModelByCache(CompanyId, ProjectId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetCompanyProjectMappingList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyProjectMappingBLL.GetList(strWhere);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<CompanyProjectMapping> GetCompanyProjectMappingModelList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyProjectMappingBLL.GetModelList(strWhere);
            //}
            //return new List<CompanyProjectMapping>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<CompanyProjectMapping> DataTableToCompanyProjectMappingList(DataTable dt)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyProjectMappingBLL.DataTableToList(dt);
            //}
            //return new List<CompanyProjectMapping>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetAllCompanyProjectMappingList()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyProjectMappingBLL.GetAllList();
            //}
            //return null;
        }
        #endregion  CompanyProjectMapping

        #region  ContactPerson
        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public int GetMaxContactPersonId()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ContactPersonBLL.GetMaxId();
            //}
            //return -1;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool ExistsContactPerson(int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ContactPersonBLL.Exists(PersonId);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public int AddContactPerson(ContactPerson model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ContactPersonBLL.Add(model);
            //}
            //return -1;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void UpdateContactPerson(ContactPerson model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                ContactPersonBLL.Update(model);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void DeleteContactPerson(int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                ContactPersonBLL.Delete(PersonId);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public ContactPerson GetContactPersonModel(int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ContactPersonBLL.GetModel(PersonId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public ContactPerson GetContactPersonByCache(int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ContactPersonBLL.GetModelByCache(PersonId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetContactPersonList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ContactPersonBLL.GetList(strWhere);
            //}
           //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<ContactPerson> GetContactPersonModelList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ContactPersonBLL.GetModelList(strWhere);
            //}
            //return new List<ContactPerson>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<ContactPerson> DataTableToContactPersonList(DataTable dt)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ContactPersonBLL.DataTableToList(dt);
            //}
            //return new List<ContactPerson>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetAllContactPersonList()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ContactPersonBLL.GetAllList();
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<DataSet> GetContactPersonInfoData(int personId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                List<DataSet> oReturn = new List<DataSet>();
                DataSet dsPerson = ContactPersonBLL.GetList(" PersonId=" + personId);
                DataSet dsPP = PersonProjectMappingBLL.GetList(" PersonId=" + personId);
                DataSet dsCP = CompanyPersonMappingBLL.GetList(" PersonId=" + personId);
                DataSet dsCompany = CompanyBLL.GetAllList();
                DataSet dsProject = ProjectBLL.GetAllList();
                DataSet dsFunction = FunctionsBLL.GetAllList();

                oReturn.Add(dsPerson);
                oReturn.Add(dsPP);
                oReturn.Add(dsCP);
                oReturn.Add(dsCompany);
                oReturn.Add(dsProject);
                oReturn.Add(dsFunction);

                return oReturn;
            //}
            //return new List<DataSet>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<DataSet> GetContactPersonInitialData()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                List<DataSet> oReturn = new List<DataSet>();
                DataSet dsCompany = CompanyBLL.GetAllList();
                DataSet dsProject = ProjectBLL.GetAllList();
                DataSet dsFunction = FunctionsBLL.GetAllList();
                oReturn.Add(dsCompany);
                oReturn.Add(dsProject);
                oReturn.Add(dsFunction);

                return oReturn;
            //}
            //return new List<DataSet>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<DataSet> SaveNewContactPerson(ContactPerson person, string companyId, string projectId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                try
                {
                    int personId = ContactPersonBLL.Add(person);

                    string[] arrCompany = companyId.Split(new Char[] { '|' });
                    foreach (string i in arrCompany)
                    {
                        CompanyPersonMapping mapping = new CompanyPersonMapping();
                        mapping.CompanyId = Convert.ToInt32(i);
                        mapping.PersonId = personId;
                        CompanyPersonMappingBLL.Add(mapping);
                    }

                    if (!String.IsNullOrEmpty(projectId))
                    {
                        string[] arrProject = projectId.Split(new Char[] { '|' });
                        foreach (string i in arrProject)
                        {
                            PersonProjectMapping mapping = new PersonProjectMapping();
                            mapping.ProjectId = Convert.ToInt32(i);
                            mapping.PersonId = personId;
                            PersonProjectMappingBLL.Add(mapping);
                        }
                    }

                    List<DataSet> retObject = new List<DataSet>();
                    DataSet dsPerson = ContactPersonBLL.GetList(" PersonId=" + personId);
                    retObject.Add(dsPerson);

                    DataSet dsCP = CompanyPersonMappingBLL.GetList(" PersonId=" + personId);
                    retObject.Add(dsCP);

                    DataSet dsPP = PersonProjectMappingBLL.GetList(" PersonId=" + personId);
                    retObject.Add(dsPP);

                    return retObject;
                }
                catch (Exception)
                {
                    return null;
                }
            //}
            //return new List<DataSet>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<DataSet> SaveContactPerson(ContactPerson person, string companyId, string projectId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                ContactPersonBLL.Update(person);

                CompanyPersonMappingBLL.Delete(person.PersonId);
                string[] arrCompany = companyId.Split(new Char[] { '|' });
                foreach (string i in arrCompany)
                {
                    CompanyPersonMapping mapping = new CompanyPersonMapping();
                    mapping.CompanyId = Convert.ToInt32(i);
                    mapping.PersonId = person.PersonId;
                    CompanyPersonMappingBLL.Add(mapping);
                }

                PersonProjectMappingBLL.Delete(person.PersonId);
                if (!String.IsNullOrEmpty(projectId))
                {
                    string[] arrProject = projectId.Split(new Char[] { '|' });
                    foreach (string i in arrProject)
                    {
                        PersonProjectMapping mapping = new PersonProjectMapping();
                        mapping.ProjectId = Convert.ToInt32(i);
                        mapping.PersonId = person.PersonId;
                        PersonProjectMappingBLL.Add(mapping);
                    }
                }

                List<DataSet> retObject = new List<DataSet>();
                DataSet dsPerson = ContactPersonBLL.GetList(" PersonId=" + person.PersonId);
                retObject.Add(dsPerson);

                DataSet dsCP = CompanyPersonMappingBLL.GetList(" PersonId=" + person.PersonId);
                retObject.Add(dsCP);

                DataSet dsPP = PersonProjectMappingBLL.GetList(" PersonId=" + person.PersonId);
                retObject.Add(dsPP);

                return retObject;
            //}
            //return new List<DataSet>();
        }

        [WebMethod]
        public bool UploadVisitCard(Int32 personId, byte[] fs, String fileName, Int32 uploadType)
        {
            try
            {
                MemoryStream ms = new MemoryStream(fs);
                String strPath = Server.MapPath("VisitCard\\" + personId);
                if (!Directory.Exists(strPath))
                {
                    Directory.CreateDirectory(strPath);
                }
                string strFile = strPath + "\\" + fileName;

                ContactPerson person = ContactPersonBLL.GetModel(personId);
                if (uploadType.Equals(0))
                {
                    person.VisitCardFace = fileName;
                }
                else
                {
                    person.VisitCardBack = fileName;
                }
                ContactPersonBLL.Update(person);

                FileStream fl = new FileStream(strFile, FileMode.OpenOrCreate);
                ms.WriteTo(fl);
                ms.Close();
                fl.Close();
                ms = null;
                fl = null;
                return true;
            }
            catch
            {
                return false;
            }
        }

        [WebMethod]
        public byte[] DownloadVisitCard(Int32 personId, String fileName)
        {
            String strPath = Server.MapPath("VisitCard\\" + personId + "\\" + fileName);
            if (File.Exists(strPath))
            {
                FileStream fs = new FileStream(strPath, FileMode.Open, FileAccess.Read);
                byte[] fileData = new Byte[fs.Length];
                fs.Read(fileData, 0, (int)fs.Length);
                fs.Close();
                return fileData;
            }

            return null;
        }

        [WebMethod]
        public bool DeleteVisitCard(Int32 personId, String fileName, Int32 fileType)
        {
            try
            {
                ContactPerson person = ContactPersonBLL.GetModel(personId);
                if (fileType.Equals(0))
                {
                    person.VisitCardFace = String.Empty;
                }
                else
                {
                    person.VisitCardBack = String.Empty;
                }
                ContactPersonBLL.Update(person);

                String strPath = Server.MapPath("VisitCard\\" + personId + "\\" + fileName);
                if (File.Exists(strPath))
                {
                    File.Delete(strPath);
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion  ContactPerson

        #region  PersonProjectMapping
        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public int GetMaxPersonProjectMappingId()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return PersonProjectMappingBLL.GetMaxId();
            //}
            //return -1;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool ExistsPersonProjectMapping(int ProjectId, int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return PersonProjectMappingBLL.Exists(ProjectId, PersonId);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void AddPersonProjectMapping(PersonProjectMapping model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                PersonProjectMappingBLL.Add(model);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void UpdatePersonProjectMapping(PersonProjectMapping model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                PersonProjectMappingBLL.Update(model);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void DeletePersonProjectMapping(int ProjectId, int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                PersonProjectMappingBLL.Delete(ProjectId, PersonId);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public PersonProjectMapping GetPersonProjectMappingModel(int ProjectId, int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return PersonProjectMappingBLL.GetModel(ProjectId, PersonId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public PersonProjectMapping GetPersonProjectMappingByCache(int ProjectId, int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return PersonProjectMappingBLL.GetModelByCache(ProjectId, PersonId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetPersonProjectMappingList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return PersonProjectMappingBLL.GetList(strWhere);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<PersonProjectMapping> GetPersonProjectMappingModelList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return PersonProjectMappingBLL.GetModelList(strWhere);
            //}
            //return new List<PersonProjectMapping>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<PersonProjectMapping> DataTableToPersonProjectMappingList(DataTable dt)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return PersonProjectMappingBLL.DataTableToList(dt);
            //}
            //return new List<PersonProjectMapping>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetAllPersonProjectMappingList()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return PersonProjectMappingBLL.GetAllList();
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<PersonProjectMapping> GetPersonProjectByPersonId(int personId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return PersonProjectMappingBLL.GetModelByPersonId(personId);
            //}
            //return new List<PersonProjectMapping>();
        }
        #endregion  PersonProjectMapping

        #region  Project
        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public int GetMaxProjectId()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ProjectBLL.GetMaxId();
            //}
            //return -1;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool ExistsProject(int ProjectId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ProjectBLL.Exists(ProjectId);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void AddProject(Project model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                ProjectBLL.Add(model);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void UpdateProject(Project model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                ProjectBLL.Update(model);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void DeleteProject(int ProjectId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                ProjectBLL.Delete(ProjectId);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public Project GetProjectModel(int ProjectId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ProjectBLL.GetModel(ProjectId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public Project GetProjectModelByCache(int ProjectId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ProjectBLL.GetModelByCache(ProjectId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetProjectList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ProjectBLL.GetList(strWhere);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<Project> GetProjectModelList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ProjectBLL.GetModelList(strWhere);
            //}
            //return new List<Project>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<Project> DataTableToProjectList(DataTable dt)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ProjectBLL.DataTableToList(dt);
            //}
            //return new List<Project>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetAllProjectList()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return ProjectBLL.GetAllList();
            //}
            //return null;
        }
        #endregion  Project

        #region  CompanyPersonMapping
        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public int GetMaxCompanyPersonMappingId()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyPersonMappingBLL.GetMaxId();
            //}
            //return -1;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool ExistsCompanyPersonMapping(int CompanyId, int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyPersonMappingBLL.Exists(CompanyId, PersonId);
            //}
            //return false;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void AddCompanyPersonMapping(CompanyPersonMapping model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                CompanyPersonMappingBLL.Add(model);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void UpdateCompanyPersonMapping(CompanyPersonMapping model)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                CompanyPersonMappingBLL.Update(model);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public void DeleteCompanyPersonMapping(int CompanyId, int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                CompanyPersonMappingBLL.Delete(CompanyId, PersonId);
            //}
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public CompanyPersonMapping GetCompanyPersonMappingModel(int CompanyId, int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyPersonMappingBLL.GetModel(CompanyId, PersonId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public CompanyPersonMapping GetCompanyPersonMappingByCache(int CompanyId, int PersonId)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyPersonMappingBLL.GetModelByCache(CompanyId, PersonId);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetCompanyPersonMappingList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyPersonMappingBLL.GetList(strWhere);
            //}
            //return null;
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<CompanyPersonMapping> GetCompanyPersonMappingModelList(string strWhere)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyPersonMappingBLL.GetModelList(strWhere);
            //}
            //return new List<CompanyPersonMapping>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public List<CompanyPersonMapping> DataTableToCompanyPersonMappingList(DataTable dt)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyPersonMappingBLL.DataTableToList(dt);
            //}
            //return new List<CompanyPersonMapping>();
        }

        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public DataSet GetAllCompanyPersonMappingList()
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                return CompanyPersonMappingBLL.GetAllList();
            //}
            //return null;
        }
        #endregion  CompanyPersonMapping

        #region CompanyProjectMapping
        //[SoapHeader("vsaHeader")]
        [WebMethod]
        public bool BatchAddCompanyProjectMapping(int companyId, List<int> addingList, List<int> deleteingList)
        {
            //if (AuthCheck.Check(vsaHeader.UserName, vsaHeader.Password))
            //{
                bool isSuccess = false;
                foreach (int id in addingList)
                {
                    if (!CompanyProjectMappingBLL.Exists(companyId, id))
                    {
                        CompanyProjectMapping companyProjectMapping = new CompanyProjectMapping();
                        companyProjectMapping.CompanyId = companyId;
                        companyProjectMapping.ProjectId = id;
                        companyProjectMapping.CreateDate = DateTime.Now;
                        CompanyProjectMappingBLL.Add(companyProjectMapping);
                    }
                }

                foreach (int id in deleteingList)
                {
                    if (CompanyProjectMappingBLL.Exists(companyId, id))
                    {
                        CompanyProjectMappingBLL.Delete(companyId, id);
                    }
                }
                return isSuccess;
            //}
            //return false;
        }
        
        #endregion
    }
}